﻿using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HM
{
    [HotUpdate]
    [Description("直接调拨单，填写物流单号时物流信息表新增行")]
    public class DataChangeWLDH: AbstractBillPlugIn
    {
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            base.BeforeSave(e);
            int row= this.View.Model.GetEntryRowCount("FBillEntry");
            if (row > 0)
            {
                int a = 0;
                string F_RXWU_Base6 = "";
                this.View.Model.DeleteEntryData("F_RXWU_SalOrderTrace");
                for (int i = 0; i < row; i++)
                {
                    //if (this.Model.GetValue("F_RXWU_Text6", i) == null &&
                    //    Convert.ToString(this.Model.GetValue("F_RXWU_Text6", i)) == "" &&
                    //    Convert.ToString(this.Model.GetValue("F_RXWU_Text6", i)) == " " && i > 0)
                    //{
                    //    a = i - 1;
                    //}
                    if(this.Model.GetValue("F_RXWU_Text6", i)!=null&& 
                        Convert.ToString(this.Model.GetValue("F_RXWU_Text6", i)) != ""&&
                        Convert.ToString(this.Model.GetValue("F_RXWU_Text6", i)) != " ")
                    {
                        this.View.Model.CreateNewEntryRow("F_RXWU_SalOrderTrace");
                        if(this.Model.GetValue("F_RXWU_Base6",i)!=null &&
                        Convert.ToString(this.Model.GetValue("F_RXWU_Base6", i)) != "" &&
                        Convert.ToString(this.Model.GetValue("F_RXWU_Base6", i)) != " ")
                        {
                            F_RXWU_Base6 = Convert.ToString((this.Model.GetValue("F_RXWU_Base6", i) as Kingdee.BOS.Orm.DataEntity.DynamicObject)["Id"]);
                            this.Model.SetValue("F_RXWU_LogComId", F_RXWU_Base6, a);
                        }
                        this.Model.SetValue("F_RXWU_CarryBillNo", this.Model.GetValue("F_RXWU_Text6", i), a);
                        a++;
                    }
                }
                this.View.UpdateView("F_RXWU_SalOrderTrace");
            }
            
        }
    }
}
